package yang.yu.sunny.domain.sales;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import yang.yu.sunny.domain.AbstractEntity;

import java.util.Date;

/**
 * 产品定价实体.记录
 * Created by yyang on 16/3/23.
 */
public class ProductPrice extends AbstractEntity implements Comparable<ProductPrice> {

    private Long productId;

    private double unitPrice;

    private Date fromTime = new Date();

    protected ProductPrice() {
    }

    public ProductPrice(Long productId, double unitPrice) {
        this(productId, unitPrice, new Date());
    }

    public ProductPrice(Long productId, double unitPrice, Date fromTime) {
        this.productId = productId;
        this.unitPrice = unitPrice;
        this.fromTime = fromTime;
    }

    public Long getProductId() {
        return productId;
    }

    public double getUnitPrice() {
        return unitPrice;
    }

    public Date getFromTime() {
        return fromTime;
    }

    @Override
    public int compareTo(ProductPrice o) {
        return this.getFromTime().compareTo(o.getFromTime());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (!(o instanceof ProductPrice)) return false;

        ProductPrice price = (ProductPrice) o;

        return new EqualsBuilder()
                .appendSuper(super.equals(o))
                .append(getProductId(), price.getProductId())
                .append(getFromTime(), price.getFromTime())
                .isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37)
                .appendSuper(super.hashCode())
                .append(getProductId())
                .append(getFromTime())
                .toHashCode();
    }
}
